package duyd.jpa.training.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Version;

@Entity
@Table(name = "HOBBY")
public class Hobby {

	private Long id;

	private String name;

	private int version;

	private Set<Contact> contacts = new HashSet<Contact>();

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "HOBBY_ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "HOBBY_NAME")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Version
	@Column(name = "HOBBY_VERSION")
	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	@ManyToMany
	@JoinTable(name = "CONTACT_HOBBY_DETAIL", inverseJoinColumns = @JoinColumn(name = "CONTACT_ID"), joinColumns = @JoinColumn(name = "HOBBY_ID"))
	public Set<Contact> getContacts() {
		return contacts;
	}

	public void setContacts(Set<Contact> contacts) {
		this.contacts = contacts;
	}

	public String toString() {
		return "Hobby[Id:" + id + ", name: " + name + "]";
	}
}
